///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function collsum_LoadURL(url)
{
    // Set the browser window's location to the incoming URL
    window._content.document.location = url;

    // Make sure that we get the focus
    window.content.focus();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function collsum_addSummary()
{
    var txt = '';
    var url = '';
    if (window.getSelection)
    {
        txt = window.content.getSelection();
    }
    else if (document.getSelection)
    {
        txt = document.content.getSelection();
    }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
    url = content.location.href;
    addDB(url,txt);
}

var xmlHttp

function addDB(url,str)
{
    xmlHttp = GetXmlHttpObject();
    if(xmlHttp == null)
    {
    	alert("Your browser does not support AJAX");
	return;
    }
    url = url.replace(/&/g, "%26");
    var server = "http://172.16.13.60/collsum/db.php";
    server = server + "?p=" + url + "collsum" + str ;
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("POST",server,true);
    xmlHttp.send(null);
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function stateChanged()
{
    if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
        var addsum = xmlHttp.responseText;
        var popbackground1="#777777" //specify backcolor or background image for pop window
        var windowtitle1="Collaborative Summary"  //pop window title
        var bodyattribute1=(popbackground1.indexOf(".")!=-1)? 'background="'+popbackground1+'"' : 'bgcolor="'+popbackground1+'"'
	win1 = window.open( <html><body></body></html>,"message_box","width=500,height=200,resizable=yes,scrollbars=yes" );
	win1.document.write('<html><title>'+windowtitle1+'</title><body '+bodyattribute1+'><font color="#00FF00"><br>Added Summary<br><br>'+addsum+'</font></body></html>');
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function collsum_viewSummary()
{
    view_url = content.location.href;
    viewDB(view_url);
}

var xmlHttp1

function viewDB(view_url)
{
    view_url = view_url.replace(/&/g, "%26");
    xmlHttp1 = GetXmlHttpObject();
    if(xmlHttp1 == null)
    {
        alert("Your browser does not support AJAX");
        return;
    }
    var server1 = "http://172.16.13.60/collsum/view.php";
    server1 = server1 + "?p=" + "'"+view_url+"'" ;
    xmlHttp1.onreadystatechange = stateChanged1;
    xmlHttp1.open("POST",server1,true);
    xmlHttp1.send(null);
}

function stateChanged1()
{
    if(xmlHttp1.readyState == 4 || xmlHttp1.readyState == "complete")
    {
        var summary = xmlHttp1.responseText;
        var popbackground="#777777" //specify backcolor or background image for pop window
        var windowtitle="Collaborative Summary"  //pop window title
        var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
	win1 = window.open( <html><body></body></html>,"message_box","width=500,height=200,resizable=yes,scrollbars=yes" );
	win1.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><font color="#00FF00"><br>View Summary<br><br>'+summary+'</font></body></html>');
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function collsum_help()
{
    //window.open("http://www.collsum.com/help","CollSum Help Contents");
    var windowtitle2="Collaborative Summary - Help Contents"  //pop window title
    var bodyattribute2=(popbackground2.indexOf(".")!=-1)? 'background="'+popbackground2+'"' : 'bgcolor="'+popbackground2+'"'
    win1 = window.open( <html><body></body></html>,"message_box","width=500,height=200,resizable=yes,scrollbars=yes" );
    win1.document.write('<html><title>'+windowtitle2+'</title><body '+bodyattribute2+'><font color="#00FF00"><br>Help Menu<br><br>contents<br><a href="">add summary</a><a href="">view summary</a></font></body></html>');
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////